<template>
	<view>
		<u-navbar title="分润" bgColor="#fff" class="nav" :fixed="true" :safeAreaInsetTop="true" :placeholder="true">
			<view slot="left">
				
			</view>
			<view slot="right" class="text-blue" @click="onClickRight">
				提现记录
			</view>
		</u-navbar>
		
		
		<view class="margin bg-blue radius padding-xl">
			<view class="">
				可提取余额(发票余额)
			</view>
			<view class="margin-top margin-bottom text-xxl ">
				<view class="flex  p-xs margin-bottom-sm mb-sm">
					<view class="flex-twice">{{objBalance.money || 0}}</view>
					<view class="flex-sub">
						<navigator url="./withdrawal" hover-class="none">
							<button class="cu-btn round block line-white">立即提现</button>
						</navigator>
						
					</view>
				</view>
				
			</view>
			<view class="">
				分润余额：{{objBalance.money || 0}}
			</view>
		</view>
		
		<view class="bg-white margin-top">
			
			<view class="cu-bar">
				<view class="action text-bold text-black"> 
					{{currMonth}}月扫码交易分润明细
				</view>
				<view class="content">
					
				</view>
				<view class="action">
					<navigator url="./profitDetail" hover-class="none">
						更多月份
					</navigator>
					
				</view>
			</view>
			<view class="padding-left padding-right">
				<text class="margin-right">成功交易：{{objData.summoney || 0}}</text>
				<text>累计分润：{{objData.cashmoneysum || 0}}</text>
			</view>
			<view >
				<view class="cu-list menu-avatar">
					<view class="cu-item cur"  v-for="(item, index) in detailedList" :key="index" v-if="item.order_id">
						<view class="cu-avatar radius lg" style="background-color: #1678ff;">
							<view>
								刷
							</view>
						</view>
						<view class="content">
							<view>
								<view class="text-cut">订单号：{{item.order_id}}</view>
							</view>
							<view class="text-gray text-sm flex">
								<view class="text-cut">{{format(item.createtime*1000)}}</view></view>
						</view>
						<view class="action">
							<view class="main-color text-xl">{{item.money}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="padding" v-if="detailedList.length === 0">
				<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/order.png"></u-empty>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-loadmore :status="status" class="w-pb-10" v-if="detailedList.length >= 10"/>
	</view>
</template>

<script>
import {format} from  "@/util/common.js"
	export default {
		data() {
			return {
				detailedList: [],
				format,
				objData: {},
				currMonth: null,
				objBalance: {},
				status: 'loadmore',
				page: 1,
				closeRequest: false
			}
		},
		onShow() {
			this.initDataList(1)
			this.withdrawMoney()
			this.detailedList = []
		},
		onReady() {
			let date = new Date()
			this.currMonth = date.getMonth()+1
		},
		onReachBottom () {
			if (this.detailedList.length >= 10) {
				this.status = 'loading';
				this.page = ++ this.page;
				setTimeout(() => {
					this.initDataList(this.page)
					if (this.closeRequest) this.status = 'nomore';
					else this.status = 'loading';
				}, 1500)
			}
		},
		methods: {
			async initDataList (page) {
				if (this.closeRequest) {
					this.$refs.uToast.show({
						type: 'default',
						title: '默认主题',
						message: "没有更多了",
					})
					this.status = 'nomore'
					return
				}
				let params = {
					agentid: uni.getStorageSync("YNF_INFO").user_id,
					start_time: '',
					end_time: '',
					pay_type: 1,
					page: page,
					size: 10,
					order_page: 1,
					order_size: 10
				}
				const res = await this.$API({url: '/api/index/money_log',method:"POST", data: params})
				if (res.code === 1) {
					this.objData = res.data
					
					if (res.data.list.length > 0) {
						for (let item of res.data.list) {
							this.detailedList.push(item)
						}
						this.status = 'loadmore'
					} else {
						if (this.page > 1) {
							this.status = 'nomore'
							this.$refs.uToast.show({
								type: 'default',
								title: '默认主题',
								message: "没有更多了",
							})
							this.closeRequest = true
						}
						
					}
				}
				
			},
			onClickRight () {
				uni.navigateTo({
					url: './record'
				})
			},
			async withdrawMoney () {
				const res = await this.$API({url: '/api/user/withdraw_info', method:"POST", data: ''})
				if (!res) {return}
				this.objBalance = res.data
			}
		}
	}
</script>

<style>
 page{background: #fff;}
</style>
